//
//  MNDTenderTransferWMPageController.m
//  minidai
//
//  Created by 谭谭伟 on 17/5/14.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDTenderTransferWMPageController.h"
#import "MNDTenderTransferingViewController.h"
#import "MNDTenderTransferedViewController.h"
#import "MNDCanTransferViewController.h"
#import "MNDWebViewController.h"
#import "MNDLoginUserModel.h"

@interface MNDTenderTransferWMPageController ()

@property (nonatomic, strong) NSArray *itemArray;

@end

@implementation MNDTenderTransferWMPageController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"债权转让";
    if (self.shouldCustomBack) {
        [self customBackBarButton];
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (![MNDLoginUserModel isUserLogin]) {
        [UserDefaultsTool removeForKey:kForgetGesture];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
//- (void)checkTransferDetail {
//    self.selectIndex = 1;
//}
- (NSArray *)itemArray {
    if (!_itemArray) {
        _itemArray = @[@"可转让", @"转让中", @"已转让"];
    }
    return _itemArray;
}

- (instancetype)init {
    if (self = [super init]) {
        self.titleSizeNormal = 16;
        self.titleSizeSelected = 16;
        self.menuBGColor = [UIColor whiteColor];
        self.menuViewStyle = WMMenuViewStyleLine;
        self.menuItemWidth = 65;
        self.menuHeight = 45;
        self.viewTop =  45;
        self.titleColorSelected = kColorOrange;
        self.titleColorNormal = kColorBlack;
        self.titleFontName = @"PingFangSC-Regular";
        
        [self initialBarbuttonItems];
    }
    return self;
}

- (void)initialBarbuttonItems {
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = kScreenWidth < 414? -10 : -15;
    UIImage *itemImage = [UIImage imageNamed:@"notice_help_icon"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage: itemImage
                                                                 style: UIBarButtonItemStylePlain
                                                                target: self
                                                                action: @selector(clickTransferRegularButton:)];
    item.tintColor = kColorOrange;
    
    if (@available(iOS 11.0, *)) {
        self.navigationItem.rightBarButtonItem = item;
    } else {
        self.navigationItem.rightBarButtonItems = @[spaceItem, item];
    }
}


//点击转让规则
-(void)clickTransferRegularButton:(id)sender {

    MNDWebViewController *webVC = [[MNDWebViewController alloc] init];
    webVC.webViewUrl = kCreditorHelp;
    webVC.naviBarHidden = YES;
    
    [self.navigationController pushViewController:webVC animated:YES];
}

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.itemArray.count;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"TenderTransfer" bundle:nil];
    if(index == 0){//能zhuanrang
        MNDCanTransferViewController *canTransferViewController = [storyboard instantiateViewControllerWithIdentifier:@"MNDCanTransferViewController"];
        return canTransferViewController;

    }else if(index == 1) {//转让中
        MNDTenderTransferingViewController *tenderTransferingViewController = [storyboard instantiateViewControllerWithIdentifier:@"MNDTenderTransferingViewController"];
        return tenderTransferingViewController;
    }else {//已转让
        MNDTenderTransferedViewController *tenderTransferedViewController = [storyboard instantiateViewControllerWithIdentifier:@"MNDTenderTransferedViewController"];
        return tenderTransferedViewController;
    }
 
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.itemArray[index];
    
}


- (void)customBackBarButton {
    UIImage *backImage = [UIImage imageNamed:@"navi_back_btn_black"];
    
    //创建返回按钮
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:backImage
                                                                          style:UIBarButtonItemStylePlain
                                                                         target:self
                                                                         action:@selector(backAction:)];
    //设置返回按钮的颜色
    [backBarButtonItem setTintColor:kColorBackButtonColor];
    
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = kScreenWidth < 414? -10 : -15;
    //将两个BarButtonItem都返回给NavigationItem
    if (@available(iOS 11.0, *)) {
        self.navigationItem.leftBarButtonItem = backBarButtonItem;
    } else {
        self.navigationItem.leftBarButtonItems = @[spaceItem, backBarButtonItem];
    }
}

- (void)backAction:(id)sender {
    [self.tabBarController setSelectedIndex:3];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
